package com.walter.controller;

import com.walter.annotation.SysLog;
import com.walter.common.CommonQuery;
import com.walter.common.Result;
import com.walter.entity.Menu;
import com.walter.model.vo.MenuVO;
import com.walter.service.MenuService;
import com.walter.util.ValidationUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ：ch
 * @date ：Created in 2021/5/25
 * @description：
 * @modified By：
 * @version: 1.0
 */
@Controller
@RequestMapping("/api/menu")
@Api(tags = "菜单管理")
public class MenuController {
    @Autowired
    private MenuService menuService;

    @PostMapping("find")
    @ResponseBody
    @ApiOperation("后管 查询菜单")
    public Result<List<MenuVO>> find(@RequestBody CommonQuery query){
        return Result.success(menuService.find(query));
    }

    @PostMapping("add")
    @ResponseBody
    @ApiOperation("后管 添加菜单")
    @SysLog("后管 添加菜单")
    public Result<Boolean> add(@RequestBody Menu menu){
        ValidationUtils.validateEntity(menu);
        return Result.success(menuService.add(menu));
    }

    @PostMapping("update")
    @ResponseBody
    @ApiOperation("后管 修改菜单")
    @SysLog("后管 修改菜单")
    public Result<Boolean> update(@RequestBody Menu menu){
        return Result.success(menuService.update(menu));
    }

    @GetMapping("delete/{menuId}")
    @ResponseBody
    @ApiOperation("后管 删除菜单")
    @SysLog("后管 删除菜单")
    public Result<Boolean> delete(@PathVariable Integer menuId){
        return Result.success(menuService.deleteById(menuId));
    }

    @GetMapping("findOne/{menuId}")
    @ResponseBody
    @ApiOperation("后管 查询菜单详情")
    public Result<Menu> findOne(@PathVariable Integer menuId){
        return Result.success(menuService.findOne(menuId));
    }
}
